// Playground - noun: a place where people can play

import Cocoa


/*********************************************************************
 * The Swift Language Learning  Chapter 10: Methods 
 *********************************************************************/


class Counter {
	var count = 0
	
	func increment() {
		count++
	}
	
	func incrementBy(amount: Int) {
		count += amount
	}
	
	func reset() {
		count = 0
	}
	
	class func desp()->String {
		return "class function"
	}
}

let co = Counter()
co.increment()
co.count
co.incrementBy(5)
co.count
co.reset()
co.count

let i = Counter.desp()


//mutating keyword is for struct an enumnation
struct Point {
	var x = 0.0, y = 0.0
	
	mutating func moveByX(deltaX: Double, y deltaY:Double) {
		y += deltaY
		x += deltaX
	}
	
	//self will replace by new instance
	mutating func replace(#x:Double,y:Double) {
		self = Point(x: x, y: y)
	}
	
	//static is for struct an enumnation in type methods
	static func desp() -> String {
		return "struct type function"
	}
}

var point = Point(x:1.0, y:1.0)
point.moveByX(5, y: 3)
point.x
point.y

point.replace(x: 5, y: 5)
point.x
point.y

Point.desp()


















